<template>
	<view style="height: 100%;overflow: auto; border: 1px solid rgba(1,1,1,0);" class="padding-lr padding-bottom-big margin-bottom ft-main bg-drak">
		<view class="bg-main padding-lr border-radius margin-top-sm" v-for="(item, index) in banks"
			:key="index" @click="selectAddr(item)">
			<view class="w-full dflex-wrap-w border-line">
				<image :src="item.img" mode="widthFix"></image>
			</view>
			<view class="dflex-b">
				<view class="dflex active">
					<text>银行卡号：{{item.showAccount}}</text>
				</view>
				<view  class="dflex"><!-- 
					<view class="padding-tb-sm padding-right-sm" @tap.stop="addAddr('edit', item)"><text
							class="iconfont iconbianji-01 ft-dark"></text></view> -->
					<view class="padding-tb-sm padding-left-sm" @tap.stop="removeAddr(item)"><text
							class="iconfont iconlajitong-01 ft-dark"></text></view>
				</view>
			</view>
		</view>
	
		<view class="btn-container dflex-b pos-f border-radius-big">
			<view class="tac padding-tb-sm flex1 bg-base" @click="addAddr('add')">添加银行卡银行卡</view>
		</view>
	</view>
</template>

<script>
	import {get_account,bind_account_unbind} from "../../../js_sdk/apis/user.js"
	import bankCode from "../../../js_sdk/apis/bankcode.js"
	export default {
		data() {
			return {
				// 加载更多状态
				loadmoreType: 'nomore',
				// 数据源
				banks: [],
				zidian:[{
					"id": "307584007998",
					"name": "平安银行",
					"img":"https://vkceyugu.cdn.bspapp.com/VKCEYUGU-c32e5061-f776-4423-93c4-27dfe5ea43ff/b0050b3a-bfad-4946-97ee-fc084952270c.png"
				},{
					"id": "105100000017",
					"name": "建设银行",
					"img":"https://vkceyugu.cdn.bspapp.com/VKCEYUGU-c32e5061-f776-4423-93c4-27dfe5ea43ff/8a0bf438-5bb6-4fd4-a805-8dae032cfcdd.png"
				}],
				empty: false,
				hasmore: 0,
				reqdata: {
					rows: 20,
					page: 1
				},
				scrollTop: 0,
			};
		},
		onLoad() {
			this.zidian=bankCode
		},
		onShow() {
			this.loadData();
		},
		methods: {
			removeAddr(item){
				uni.showModal({
					title: '提示',
					content: '是否解绑删除银行卡',
					success: (res)=> {
						if (res.confirm) {
							bind_account_unbind({id:item.id}).then(res=>{
								if(res.code==200){
									uni.showToast({title:"删除成功!", icon:"none"});
									this.loadData();
								}
							})
						}
					},
				})
			},
			// 添加|编辑 收货人
			addAddr(type, options) {
				options = options || {
					id: 0
				};
				uni.navigateTo({
					url: `/pages/user/bank/bank-edit?type=${type}&id=${options._id}`
				});
			},
			loadData() {
				get_account().then(res=>{
					console.log(res)
					let temp=res.data.content
					temp.forEach(v=>{
						this.zidian.forEach(v1=>{
							if(v1.id==v.bank){
								v.img=v1.img
							}
						})
					})
					this.banks=temp
				})
			},
			// 删除收藏
			deleteCollect(id) {
				let _this = this
				uni.showModal({
					title: '提示',
					content: '删除收藏',
					success: function(res) {
						if (res.confirm) {
							_this.$db[_collect].where('create_uid == $env.uid').remove(id).then(res => {
								if (res.code === 200) {
									_this.loadData();
								}
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			}
		}
	};
</script>

<style lang="scss">
	.desc {
		font-size: $font-lg;
	}
	image{
		width: 100%;
	}
	page{
		height: 100%;
	}
	.btn-container {
		left: 20rpx;
		right: 20rpx;
		bottom: 20rpx;
	}
</style>
